<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>柒拾佳护</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/icons-extra.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/main.css" />
		<style>
			ul {
				font-size: 14px;
				color: #8f8f94;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			#kefu {
				font-size: 0.5rem;
				line-height: 30px;
			}
			
			header button img {
				width: 0.3rem;
			}
			
			.mui-bar {
				box-shadow: 0 0 1px rgba(185, 185, 185, 1);
			}
			
			.mui-badge {
				min-height: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 id="title" class="mui-title">柒拾佳护</h1>
		</header>
		<nav class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item mui-active" href="subpages/tab-webview-subpage-home.html">
				<span class="mui-icon iconfont icon-sy"></span>
				<span class="mui-tab-label">首页</span>
			</a>

			<a id="dingdan" class="mui-tab-item dingdan" href="subpages/tab-webview-subpage-service.html">
				<span class="mui-icon iconfont icon-hzdd"></span>
				<span class="mui-tab-label">订单</span>
			</a>
			<a id="qiangdan" class="mui-tab-item qiangdan" href="subpages/tab-webview-subpage-order.html">
				<span class="mui-icon iconfont icon-peixun"><span id="muiBadge" class="mui-badge"></span></span>
				<span class="mui-tab-label">消息</span>
			</a>
			<a class="mui-tab-item yihuquan" href="subpages/tab-webview-subpage-talk.html">
				<span class="mui-icon iconfont icon-yhq"></span>
				<span class="mui-tab-label">医护圈</span>
			</a>

			<a class="mui-tab-item wode" href="subpages/tab-webview-subpage-my.html">
				<span class="mui-icon iconfont icon-fbz"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script type="text/javascript" src="js/xiangyingshi.js"></script>
		<script type="text/javascript" src="js/constants.js"></script>
		<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="js/sharemethods.js"></script>
		<script>
			mui.init();
			var subpages = ['subpages/tab-webview-subpage-home.html',
				'subpages/tab-webview-subpage-service.html',
				'subpages/tab-webview-subpage-order.html',
				'subpages/tab-webview-subpage-talk.html',
				'subpages/tab-webview-subpage-my.html'
			];

			var activeTab = "";
			mui.plusReady(function() {
				console.log("获得操作系统：" + plus.os.name)
				console.log("操作系统语言：" + window.navigator.language)

				plus.push.addEventListener("receive", function(msg) {
					//if(msg.aps) {//苹果消息					
					var data = JSON.parse(msg.content);
					if(data.tc == "0000002") {
						mui.openWindow({
							url: '../order/grab_order_detail.html',
							id: 'grab_order_detail',
							show: {
								autoShow: false, //页面loaded事件发生后自动显示，默认为true
								event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
							},
							waiting: {
								autoShow: true //自动显示等待框，默认为true
							},
							extras: {
								orderId: data.orderId //扩展参数
							}
						});
					} else if(data.tc == "000003") {
						$('#muiBadge').show();
						var template = plus.webview.getWebviewById("subpages/tab-webview-subpage-order.html");
						template.reload();
					}
				});

				mainPage = mui.preload({
					"url": 'subpages/tab-webview-subpage-home.html',
					"id": 'tab-webview-subpage-home.html'
				}, {
					"url": 'subpages/tab-webview-subpage-service.html',
					"id": 'tab-webview-subpage-service.html'
				}, {
					"url": 'subpages/tab-webview-subpage-order.html',
					"id": 'tab-webview-subpage-order.html'
				}, {
					"url": 'subpages/tab-webview-subpage-talk.html',
					"id": 'tab-webview-subpage-talk.html'
				}, {
					"url": 'subpages/tab-webview-subpage-my.html',
					"id": 'tab-webview-subpage-my.html'
				});

				//延迟的原因：优先打开启动导航页面，避免资源争夺
				var topoffset = '45px';

				if(plus.navigator.isImmersedStatusbar()) { // 兼容immersed状态栏模式
					// 获取状态栏高度并根据业务需求处理，这里重新计算了子窗口的偏移位置
					topoffset = (Math.round(plus.navigator.getStatusbarHeight()) + 45) + 'px';
					document.querySelector("header").style.height = topoffset;
					document.querySelector("header").style.paddingTop = "20px";
				}
				var subpage_style = {
					top: topoffset,
					bottom: '51px'
					//					color:"#4d7acf"
				};

				var aniShow = {};
				var settings = app.getSettings();

				if(localStorage.getItem("ACCESSTOKEN") == null) {
					mui.openWindow({
						url: "login/login.html"
					});
				} else {
					var self = plus.webview.currentWebview();
					for(var i = 0; i < 5; i++) {
						var temp = {};
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
						if(i > 0) {
							sub.hide();
						} else {
							temp[subpages[i]] = "true";
							mui.extend(aniShow, temp);
						}
						self.append(sub);
					}

					mui.oldBack = mui.back;
					var backButtonPress = 0;
					mui.back = function(event) {
						backButtonPress++;
						if(backButtonPress > 1) {
							plus.runtime.quit();
						} else {
							plus.storage.removeItem("roster");
							plus.nativeUI.toast('再按一次退出应用');
						}
						setTimeout(function() {
							backButtonPress = 0;
						}, 1000);
						return false;
					};

					var sussess = function(data) {
						//服务器返回响应，根据响应结果，分析是否登录成功；
						if(data.result == "success") {
							localStorage.setItem('USER', JSON.stringify(data.obj));
						} else {
							mui.toast(data.msg);
						}
					};
					commonHttpUtils(showdetailUrl, "get", {}, sussess, error);
				}

				//当前激活选项
				activeTab = subpages[0];
				var title = document.getElementById("title");
				//选项卡点击事件
				mui('.mui-bar-tab').on('tap', 'a', function(e) {
					if(this.id == 'qiangdan') {
						$('#muiBadge').hide();
					}
					var targetTab = this.getAttribute('href');
					if(targetTab == activeTab) {
						return;
					}
					var tabSpan = this.querySelector('.mui-tab-label');
					//更换标题
					title.innerHTML = tabSpan.title ? tabSpan.title : tabSpan.innerHTML;

//					if(this.id == 'dingdan') {
//						var dingdanView = plus.webview.getWebviewById("subpages/tab-webview-subpage-service.html");
//						if(dingdanView) {
//							//触发列表界面的自定义事件（refresh）,从而进行数据刷新
//							dingdanView.evalJS("initFunction()");
//						}
//					}
					//显示目标选项卡
					//若为iOS平台或非首次显示，则直接显示
					if(mui.os.ios || aniShow[targetTab]) {
						plus.webview.show(targetTab);
					} else {
						//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 300);
						plus.nativeUI.closeWaiting();
					}
					//隐藏当前;
					plus.webview.hide(activeTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});

			});
			//自定义事件，模拟点击“首页选项卡”
			document.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if(defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});

			var setItemActive = function() {
				var defaultTab = document.getElementById("dingdan");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if(defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
				activeTab = subpages[1]
			};
		</script>

	</body>

</html>